package com.biu.billiards.controller;


import com.biu.billiards.model.vo.mqtt.SendVo;


import com.biu.billiards.mqqts.MqttService;
import com.biu.billiards.response.RespGenerator;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xue
 * @since 2023-09-25
 */
@RestController
@RequestMapping()
public class MqttController {


//    @Autowired
//    private MqttMessageSender mqttMessageSender;

    @Autowired
    private MqttService mqttService;
    @ApiOperation(value = "发送")
    @PostMapping("/mqtt/send")
    public void send(@RequestBody SendVo sendVo) {

        //2023-12-05 15:28:17.999  INFO 24739 --- [ mqttx_38a2b51c] com.biu.billiards.mqqts.MyMqttCallback
        // : == MyMqttCallback ==> messageArrived 接收消息主题:
        // /corx/pub/CORX00001000，接收消息内容:
        // {"A01":0,"A02":1,"A03":0,"A04":0,"A05":0,"A06":0,"A07":0,"A08":0,"A09":1,"A10":0,"A11":0,"A12":1,"B01":0,"B02":0,"A96":1,"A97":1,"A88":1,"res":"1223"}

        System.out.println("sendVo");
        System.out.println(sendVo);

        String no = "03";
       // String openMsg = "{A"+no+":100000,res:1223}";


        String msg = "{\"A"+no+"\":110000,\"res\":\"123\"}";


        String topic = "/corx/sub/CORX00001005";

      //  String closeMsg = "{\"A"+no+"\":110000,\"res\":\"123\"}";


        System.out.println(msg);
        System.out.println(topic);
        mqttService.publish(msg,topic);





       // mqttMessageSender.send(topic,openMsg);

    }










}
